package leetcode.leetcode226;

/**
 * @author czt
 * @version 1.0
 * @since 2024/12/27
 *
 * 反转二叉树
 */
public class Leetcode226 {

    public TreeNode invertTree(TreeNode root) {
        f(root);
        return root;
    }

    // 交换其左右孩子
    private void f(TreeNode node) {
        if (node == null) {
            return;
        }
        TreeNode temp = node.left;
        node.left = node.right;
        node.right = temp;
        f(node.left);
        f(node.right);
    }

}
